home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_base64.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  8KB  |  168 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. import unittest
  5. from test import test_support
  6. import base64
  7.  
  8. class LegacyBase64TestCase(unittest.TestCase):
  9.     
  10.     def test_encodestring(self):
  11.         eq = self.assertEqual
  12.         eq(base64.encodestring('www.python.org'), 'd3d3LnB5dGhvbi5vcmc=\n')
  13.         eq(base64.encodestring('a'), 'YQ==\n')
  14.         eq(base64.encodestring('ab'), 'YWI=\n')
  15.         eq(base64.encodestring('abc'), 'YWJj\n')
  16.         eq(base64.encodestring(''), '')
  17.         eq(base64.encodestring('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}'), 'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n')
  18.  
  19.     
  20.     def test_decodestring(self):
  21.         eq = self.assertEqual
  22.         eq(base64.decodestring('d3d3LnB5dGhvbi5vcmc=\n'), 'www.python.org')
  23.         eq(base64.decodestring('YQ==\n'), 'a')
  24.         eq(base64.decodestring('YWI=\n'), 'ab')
  25.         eq(base64.decodestring('YWJj\n'), 'abc')
  26.         eq(base64.decodestring('YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n'), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}')
  27.         eq(base64.decodestring(''), '')
  28.  
  29.     
  30.     def test_encode(self):
  31.         eq = self.assertEqual
  32.         StringIO = StringIO
  33.         import cStringIO
  34.         infp = StringIO('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}')
  35.         outfp = StringIO()
  36.         base64.encode(infp, outfp)
  37.         eq(outfp.getvalue(), 'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n')
  38.  
  39.     
  40.     def test_decode(self):
  41.         StringIO = StringIO
  42.         import cStringIO
  43.         infp = StringIO('d3d3LnB5dGhvbi5vcmc=')
  44.         outfp = StringIO()
  45.         base64.decode(infp, outfp)
  46.         self.assertEqual(outfp.getvalue(), 'www.python.org')
  47.  
  48.  
  49.  
  50. class BaseXYTestCase(unittest.TestCase):
  51.     
  52.     def test_b64encode(self):
  53.         eq = self.assertEqual
  54.         eq(base64.b64encode('www.python.org'), 'd3d3LnB5dGhvbi5vcmc=')
  55.         eq(base64.b64encode('\x00'), 'AA==')
  56.         eq(base64.b64encode('a'), 'YQ==')
  57.         eq(base64.b64encode('ab'), 'YWI=')
  58.         eq(base64.b64encode('abc'), 'YWJj')
  59.         eq(base64.b64encode(''), '')
  60.         eq(base64.b64encode('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}'), 'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==')
  61.         eq(base64.b64encode('\xd3V\xbeo\xf7\x1d', altchars = '*$'), '01a*b$cd')
  62.         eq(base64.standard_b64encode('www.python.org'), 'd3d3LnB5dGhvbi5vcmc=')
  63.         eq(base64.standard_b64encode('a'), 'YQ==')
  64.         eq(base64.standard_b64encode('ab'), 'YWI=')
  65.         eq(base64.standard_b64encode('abc'), 'YWJj')
  66.         eq(base64.standard_b64encode(''), '')
  67.         eq(base64.standard_b64encode('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}'), 'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==')
  68.         eq(base64.urlsafe_b64encode('\xd3V\xbeo\xf7\x1d'), '01a-b_cd')
  69.  
  70.     
  71.     def test_b64decode(self):
  72.         eq = self.assertEqual
  73.         eq(base64.b64decode('d3d3LnB5dGhvbi5vcmc='), 'www.python.org')
  74.         eq(base64.b64decode('AA=='), '\x00')
  75.         eq(base64.b64decode('YQ=='), 'a')
  76.         eq(base64.b64decode('YWI='), 'ab')
  77.         eq(base64.b64decode('YWJj'), 'abc')
  78.         eq(base64.b64decode('YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=='), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}')
  79.         eq(base64.b64decode(''), '')
  80.         eq(base64.b64decode('01a*b$cd', altchars = '*$'), '\xd3V\xbeo\xf7\x1d')
  81.         eq(base64.standard_b64decode('d3d3LnB5dGhvbi5vcmc='), 'www.python.org')
  82.         eq(base64.standard_b64decode('YQ=='), 'a')
  83.         eq(base64.standard_b64decode('YWI='), 'ab')
  84.         eq(base64.standard_b64decode('YWJj'), 'abc')
  85.         eq(base64.standard_b64decode(''), '')
  86.         eq(base64.standard_b64decode('YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=='), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}')
  87.         eq(base64.urlsafe_b64decode('01a-b_cd'), '\xd3V\xbeo\xf7\x1d')
  88.  
  89.     
  90.     def test_b64decode_error(self):
  91.         self.assertRaises(TypeError, base64.b64decode, 'abc')
  92.  
  93.     
  94.     def test_b32encode(self):
  95.         eq = self.assertEqual
  96.         eq(base64.b32encode(''), '')
  97.         eq(base64.b32encode('\x00'), 'AA======')
  98.         eq(base64.b32encode('a'), 'ME======')
  99.         eq(base64.b32encode('ab'), 'MFRA====')
  100.         eq(base64.b32encode('abc'), 'MFRGG===')
  101.         eq(base64.b32encode('abcd'), 'MFRGGZA=')
  102.         eq(base64.b32encode('abcde'), 'MFRGGZDF')
  103.  
  104.     
  105.     def test_b32decode(self):
  106.         eq = self.assertEqual
  107.         eq(base64.b32decode(''), '')
  108.         eq(base64.b32decode('AA======'), '\x00')
  109.         eq(base64.b32decode('ME======'), 'a')
  110.         eq(base64.b32decode('MFRA===='), 'ab')
  111.         eq(base64.b32decode('MFRGG==='), 'abc')
  112.         eq(base64.b32decode('MFRGGZA='), 'abcd')
  113.         eq(base64.b32decode('MFRGGZDF'), 'abcde')
  114.  
  115.     
  116.     def test_b32decode_casefold(self):
  117.         eq = self.assertEqual
  118.         eq(base64.b32decode('', True), '')
  119.         eq(base64.b32decode('ME======', True), 'a')
  120.         eq(base64.b32decode('MFRA====', True), 'ab')
  121.         eq(base64.b32decode('MFRGG===', True), 'abc')
  122.         eq(base64.b32decode('MFRGGZA=', True), 'abcd')
  123.         eq(base64.b32decode('MFRGGZDF', True), 'abcde')
  124.         eq(base64.b32decode('me======', True), 'a')
  125.         eq(base64.b32decode('mfra====', True), 'ab')
  126.         eq(base64.b32decode('mfrgg===', True), 'abc')
  127.         eq(base64.b32decode('mfrggza=', True), 'abcd')
  128.         eq(base64.b32decode('mfrggzdf', True), 'abcde')
  129.         self.assertRaises(TypeError, base64.b32decode, 'me======')
  130.         eq(base64.b32decode('MLO23456'), 'b\xdd\xad\xf3\xbe')
  131.         eq(base64.b32decode('M1023456', map01 = 'L'), 'b\xdd\xad\xf3\xbe')
  132.         eq(base64.b32decode('M1023456', map01 = 'I'), 'b\x1d\xad\xf3\xbe')
  133.  
  134.     
  135.     def test_b32decode_error(self):
  136.         self.assertRaises(TypeError, base64.b32decode, 'abc')
  137.         self.assertRaises(TypeError, base64.b32decode, 'ABCDEF==')
  138.  
  139.     
  140.     def test_b16encode(self):
  141.         eq = self.assertEqual
  142.         eq(base64.b16encode('\x01\x02\xab\xcd\xef'), '0102ABCDEF')
  143.         eq(base64.b16encode('\x00'), '00')
  144.  
  145.     
  146.     def test_b16decode(self):
  147.         eq = self.assertEqual
  148.         eq(base64.b16decode('0102ABCDEF'), '\x01\x02\xab\xcd\xef')
  149.         eq(base64.b16decode('00'), '\x00')
  150.         self.assertRaises(TypeError, base64.b16decode, '0102abcdef')
  151.         eq(base64.b16decode('0102abcdef', True), '\x01\x02\xab\xcd\xef')
  152.  
  153.  
  154.  
  155. def suite():
  156.     suite = unittest.TestSuite()
  157.     suite.addTest(unittest.makeSuite(LegacyBase64TestCase))
  158.     suite.addTest(unittest.makeSuite(BaseXYTestCase))
  159.     return suite
  160.  
  161.  
  162. def test_main():
  163.     test_support.run_suite(suite())
  164.  
  165. if __name__ == '__main__':
  166.     unittest.main(defaultTest = 'suite')
  167.  
  168.